﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FireBomb : MonoBehaviour
{
    public float range;
    public int damage;
    public PlayerType targetOwner;

    public float finishTime;
    public float finishTimer = 0;

    private void Start()
    {
        TriggerMagic();
        
    }

    private void Update()
    {
        finishTimer += Time.deltaTime;
        if(finishTimer>finishTime)
        {
            Destroy(this);
        }
    }
    public void TriggerMagic()
    {
        LayerMask l = LayerMask.NameToLayer(LayerNameSet.Unit);
        Collider[] colliders = Physics.OverlapSphere(transform.position, range,LayerMask.GetMask(LayerNameSet.Unit) );
        foreach(var c in colliders)
        {
            var ai = c.GetComponent<SoldierAI>();
            if (ai!=null && ai.warrior.unitOwner == targetOwner)
            {
                
                var warrior = ai.GetComponent<Warrior>();
                if (warrior!= null)
                {
                    AttackInfo attack = new AttackInfo()
                    {   HitPoint = damage,
                        type = AttackType.MagicAttack,
                        AttackOriginPos = transform.position };
                    warrior.GetHit(attack);
                }
            }
        }
    }

    
}
